package com.zhome.gateway.config;

import com.google.common.util.concurrent.RateLimiter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 *
 * @author cuiyh9
 * @date 2020/5/9
 */
@Configuration
public class RateLimiterConfig {

    /**
     * TODO 此处暂时休眠500ms,防止启动服务器时，访问量过大，导致限流生效。
     * 后续需要了解一下其他处理方案
     * @return
     * @throws Exception
     */
    @Bean
    public RateLimiter rateLimiter() throws Exception {
        RateLimiter rateLimiter =  RateLimiter.create(1000);
        TimeUnit.MILLISECONDS.sleep(500);;
        return rateLimiter;
    }
}
